package com.ara.account.activity;

import android.os.Bundle;

import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.ara.account.R;
import com.ara.account.bean.AccountBean;
import com.ara.account.constant.AccountRouterApiConstant;
import com.ara.account.contract.LoginContract;
import com.ara.account.databinding.AccountActivityLoginBinding;
import com.ara.account.presenter.LoginPresenter;
import com.ara.account.util.AccountUtils;
import com.ara.common.kernel.base.BaseMvpActivity;
import com.ara.common.kernel.network.exception.ExceptionHandle;
import com.ara.common.kernel.util.ToastUtils;


/**
 * Created by XieXin on 2018/12/10.
 * 登录 页面
 */
@Route(path = AccountRouterApiConstant.API_LOGIN)
public class LoginActivity extends BaseMvpActivity<AccountActivityLoginBinding, LoginContract.View, LoginPresenter>
        implements LoginContract.View {

    @Override
    public void initView(@Nullable Bundle savedInstanceState) {
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected LoginPresenter createPresenter() {
        return new LoginPresenter(this);
    }

    @Override
    public void onLoginSuccess(AccountBean bean) {
        AccountUtils.setIsLogin(true);
        AccountUtils.setToken(bean.getToken());
        AccountUtils.setAccount(bean);
//        RouterApiHolder.jumpTrainMainActivity();
        finish();

//        AccountUtils.setAccount(bean);
//        RouterApiHolder.jumpActionDetailsTempActivity();
//        finish();
    }

    @Override
    public void showLoadingProgress() {
//        showLoadingDialog();
    }

    @Override
    public void dismissLoadingProgress() {
//        dismissLoadingDialog();
    }

    @Override
    public void onError(int requestCode, ExceptionHandle.ResponseThrowable e) {
//        if (customScanFaceView != null) customScanFaceView.setStopFrameProcessor(false);
//        isUpdate = false;
    }

    @Override
    public void onToast(ExceptionHandle.ResponseThrowable e) {
        onBaseToast(e);
    }

    private long startTime = 0;

    @Override
    public void onBackPressed() {
        if (System.currentTimeMillis() - startTime > 2 * 1000) {
            ToastUtils.showShort(this, R.string.press_again_exit);
            startTime = System.currentTimeMillis();
        } else {
            super.onBackPressed();
        }
    }
}
